package com.mop.core.es.dao.plugins;

import com.lemon.core.common.lang.util.Assert;
import com.lemon.core.common.lang.util.ObjectUtils;
import com.mop.core.es.dao.plugins.wraper.QueryWraper;
import org.apache.poi.ss.formula.functions.T;

import java.io.Serializable;
import java.util.List;

/**
 * @author lemon
 * @ClassName Pagination
 * @desc 分页插件
 * @Date 2018/12/12 17:16
 * @Version 1.0
 **/
public class Pagination<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private T entity;

    private QueryWraper<T> queryWraper;

    /**
     * 每页显示条数，默认 10
     */
    private Integer size = 10;

    /**
     * 当前页
     */
    private Integer current = 1;

    /**
     * <p>
     * ES 排序 ASC 集合
     * </p>
     */
    private List<String> ascs;
    /**
     * <p>
     * ES 排序 DESC 集合
     * </p>
     */
    private List<String> descs;

    /**
     * <p>
     * ES 排序 sort order
     * </p>
     */
    private List<String> orderByFields;

    public T getEntity() {
        Assert.notNull(entity, "entityr不可为空!");
        return entity;
    }

    public void setEntity(T entity) {
        this.entity = entity;
    }

    public QueryWraper<T> getQueryWraper() {
        if (ObjectUtils.isEmpty(queryWraper)) {
            QueryWraper<T> queryWraper = new QueryWraper<T>();
            queryWraper.setEntity(entity);
            this.queryWraper = queryWraper;
        }
        return queryWraper;
    }

    public void setQueryWraper(QueryWraper<T> queryWraper) {
        this.queryWraper = queryWraper;
    }

    public Integer getSize() {
        return size;
    }

    public void setSize(Integer size) {
        this.size = size;
    }

    public Integer getCurrent() {
        return current;
    }

    public void setCurrent(Integer current) {
        this.current = current;
    }

    public List<String> getAscs() {
        return ascs;
    }

    public void setAscs(List<String> ascs) {
        this.ascs = ascs;
    }

    public List<String> getDescs() {
        return descs;
    }

    public void setDescs(List<String> descs) {
        this.descs = descs;
    }

    public List<String> getOrderByFields() {
        return orderByFields;
    }

    public void setOrderByFields(List<String> orderByFields) {
        this.orderByFields = orderByFields;
    }
}
